<script setup>
import {onMounted, ref} from 'vue';
import {useRoute} from 'vue-router';
import request from '../plugins/request.js'
import {showFailToast, showSuccessToast} from "vant";
import UserCard from "../components/UserCard.vue";
import qs from 'qs'

const route = useRoute();
let userList = ref([])

onMounted(async () => {
  // 发送数据请求
  const userListData = await request.get('/user/search/tags', {
    params: {
      tagNameList: route.query.tags
    },
    paramsSerializer: params => {
      return qs.stringify(params, {indices: false})
    }
  }).then((response) => {
    console.log('/user/search/tags', response)
    showSuccessToast('查询成功')
    return response?.data
  }).catch((error) => {
    console.error('/user/search/tags', error)
    showFailToast('查询失败')
  })
  if (userListData) {
    userListData.forEach(item => {
      if (item.tags) {
        item.tags = JSON.parse(item.tags)
      }
    })
    userList.value = userListData;
  }
});
</script>

<template>
  <user-card v-if="userList.length>0" :user-list="userList"></user-card>
  <van-empty v-else description="暂无信息"/>
</template>

<style scoped></style>